﻿using Bids.Core.Infrastructure;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Telerik.OpenAccess;
using Telerik.OpenAccess.Metadata;
using Telerik.OpenAccess.Metadata.Fluent;
namespace Bids.Core.DomainObjects
{
	/// <summary>
	/// 心情/状态的评论
	/// </summary>
	[Serializable]
    public class MoodReply : IEntity
	{
        public MoodReply()
        {
            this.Replys = new List<MoodReply>();
        }
		
		/// <summary>
		/// 
		/// </summary>
        public virtual int ID { set; get; }
        /// <summary>
        /// 心情Id
        /// </summary>
        public virtual int MoodId { get; set; }
        /// <summary>
        /// 父Id
        /// </summary>
        public virtual int ParentId { get; set; }
		/// <summary>
		/// 发件人Id
		/// </summary>
        public virtual int UserId { set; get; }
		
		/// <summary>
		/// 正文
		/// </summary>
        public virtual string Content { set; get; }
		/// <summary>
		/// 时间
		/// </summary>
        public virtual DateTime CreateTime { set; get; }

        public virtual Mood Mood { get; set; }

        public virtual User User { get; set; }
        public IList<MoodReply> Replys { get; set; }
        public virtual MoodReply Parent { get; set; }
        public static MappingConfiguration<MoodReply> CreateConfiguration()
        {
            var threadMapping = new MappingConfiguration<MoodReply>();
            threadMapping.MapType(t => new
            {
                t.ID,
                t.MoodId,
                t.ParentId,
                t.UserId,
                t.Content,
                t.CreateTime

            }).ToTable("MoodReplys");
            threadMapping.HasProperty(t => t.ID).IsIdentity(KeyGenerator.Autoinc);
            threadMapping.HasAssociation(t => t.Mood).WithOpposite(d => d.MoodReplys).HasConstraint((t, d) => t.MoodId == d.ID);
            threadMapping.HasAssociation(t => t.User).WithOpposite(d => d.MoodReplys).HasConstraint((t, d) => t.UserId == d.ID);
            threadMapping.HasAssociation(t => t.Parent).WithOpposite(t => t.Replys).HasConstraint((t, d) => t.ParentId == d.ID);
            return threadMapping;
        }
	}

}

